﻿using System;
using NUnit.Framework;

namespace CodeContrib.Tests
{
	public class CalculatorTests
	{
		[Test]
		public void Calculator_Calculate_With_1000_DividedBy_10_Percent_ShouldReturn_10()
		{
			// Arrange
			var formula = "(1000 / 10%)";

			// Act
			var result = formula.Calculate();

			// Assert
			Assert.AreEqual(10, result);
		}

		[Test]
		public void Calculator_Calculate_With_1000_Minus_10_Percent_ShouldReturn_900()
		{
			// Arrange
			var formula = "(1000 - 10%)";

			// Act
			var result = formula.Calculate();

			// Assert
			Assert.AreEqual(900, result);
		}

		[Test]
		public void Calculator_Calculate_With_1000_MultipliedBy_10_Percent_ShouldReturn_100000()
		{
			// Arrange
			var formula = "(1000 * 10%)";

			// Act
			var result = formula.Calculate();

			// Assert
			Assert.AreEqual(100000, result);
		}

		[Test]
		public void Calculator_Calculate_With_1000_Plus_10_Percent_ShouldReturn_1100()
		{
			// Arrange
			var formula = "(1000 + 10%)";

			// Act
			var result = formula.Calculate();

			// Assert
			Assert.AreEqual(1100, result);
		}

		[Test]
		[ExpectedException(typeof (ArgumentException))]
		public void Calculator_Calculate_With_10_Percent_Plus_1000_ShouldThrow_ArgumentException()
		{
			// Arrange
			var formula = "(10% + 1000)";

			// Act
			formula.Calculate();
		}

		[Test]
		[ExpectedException(typeof (DivideByZeroException))]
		public void Calculator_Calculate_With_1_DividedBy_0_ShouldThrow_DivideByZeroException()
		{
			// Arrange
			var formula = "(1/0)";

			// Act
			formula.Calculate();
		}

		[Test]
		public void Calculator_Calculate_With_1_Plus_1_ShouldReturn_2()
		{
			// Arrange
			var formula = "(1 + 1)";

			// Act
			var result = formula.Calculate();

			// Assert
			Assert.AreEqual(2, result);
		}
	}
}